import Vue from 'vue'
import Router from 'vue-router'

// 批量导入路由
let routes = []

// 指定只打包具体 router
if (process.env.NODE_ENV === 'production') {
  // 正式环境
  routes = routes.concat(
    require('@/router/page1.js').default,
    require('@/router/page2.js').default
  )
} else {
  // 开发环境
  routes = routes.concat(
    require('@/router/page1.js').default,
    require('@/router/page2.js').default,
    [
      {
        path: '/',
        name: 'navDev',
        meta: { title: '快捷导航-dev' },
        component: {
          render () {
            const h2Style = { padding: '20px 6px 0', 'font-size': '16px' }
            const pStyle = { padding: '4px 10px' }
            const aStyle = { color: 'blue', 'text-decoration': 'underline' }
            const links = []
            routes.forEach(route => {
              links.push(<p style={pStyle}><router-link to={route.path} style={aStyle}>{route.meta ? route.meta.title : route.path}</router-link></p>)
            })

            return (
              <div>
                <h2 style={h2Style}>页面</h2>
                {links}
              </div>
            )
          }
        }
      }
    ])
}

// 404
routes.push(
  {
    path: '*',
    name: '404',
    meta: { title: '404', zIndex: 99 },
    component: {
      render () {
        return <div style="height:200px;font-size:30px;display:flex;align-items:center;justify-content: center;">404：没有这个页面(⊙﹏⊙)</div>
      }
    }
  }
)

Vue.use(Router)
export default new Router({
  routes
})
